#include "oltray.h"
#include "ui_oltray.h"
#include <QSettings>
#include <QMessageBox>

OLTray::OLTray(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::OLTray)
{    
    ui->setupUi(this);

    this->setWindowTitle("Outlook MinToTray");
    officeVersion.insert(tr("office2003"),tr("11.0"));
    officeVersion.insert(tr("office2007"),tr("12.0"));
    officeVersion.insert(tr("office2010"),tr("14.0"));
    officeVersion.insert(tr("office2013"),tr("15.0"));
    officeVersion.insert(tr("office2016"),tr("16.0"));

    QMap<QString,QString>::iterator it;

    for(it=officeVersion.begin();it!=officeVersion.end();it++){
        ui->cbb_OfficeVersion->addItem(it.key());
    }

    ui->cbb_OfficeVersion->setCurrentIndex(1);
}

OLTray::~OLTray()
{
    delete ui;
}

void OLTray::on_pushButton_clicked()
{
    QString selOfice=ui->cbb_OfficeVersion->currentText();

    QString selVersion = officeVersion[selOfice];

    QString regKey = QString("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Office\\%0\\Outlook\\Preferences").arg(selVersion);
    //QDebug(regKey);
    QSettings reg(regKey,QSettings::NativeFormat);

    reg.setValue("MinToTray",1);

    QMessageBox::information(this,"Info","Change Success!",QMessageBox::Ok);
}
